package com.qidian.buy.util.pojo;

import com.qidian.buy.util.Const;

/**
 * @Author 郭浩
 */
public class QDResult<T> {
    private int code;
    private String msg;
    private T data;

    public QDResult() {
    }
    public QDResult(int code, T data) {
        this.code = code;
        this.data = data;
    }
    public QDResult(int code) {
        this.code = code;
    }
    public QDResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static QDResult notFound(){
        QDResult ok = QDResult.ok();
        ok.setCode(Const.RESPONSE_STATUS_NOT_FOUND);
        return ok;
    }

    public QDResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static QDResult ok(){
        return new QDResult(200);
    }
    public static QDResult ok(String msg){
        return new QDResult(200,msg);
    }
    public static QDResult ok(Object obj){
        return new QDResult(200,obj);
    }
    public static QDResult ok(String msg,Object obj){
        return new QDResult(200,msg,obj);
    }

    public static QDResult fal(){
        return new QDResult(Const.RESPONSE_STATUS_ERROR);
    }
    public static QDResult fal(int code){
        return new QDResult(code,"重复");
    }
    public static QDResult fal(String msg){
        return new QDResult(500,msg);
    }

    public static QDResult fal(int code,String msg){
        return new QDResult(code,msg);
    }

    public static QDResult none(){
        return new QDResult(404);
    }
    public static QDResult none(String msg){
        return new QDResult(404,msg);
    }
    public static QDResult error(){
        QDResult fal = fal();
        fal.setCode(Const.RESPONSE_STATUS_ERROR);
        return fal;
    }
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
